package com.gskj.oss.controller;

import com.gskj.commonutils.ResultJson;
import com.gskj.oss.service.IOssService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.ws.rs.POST;
import java.util.Objects;

/**
 * @author :CodingFarmer_码农  Connor(康纳)_郭
 * @date : 13:49 20.5.15
 * @Company : http://www.gskj.com
 * @Version : 1.0
 */

@RestController
@RequestMapping("/eduoss/fileoss")
@CrossOrigin
public class OssController {

    @Autowired
    private IOssService iOssService;

    /***
     *  上传 头像
     * @param file
     * @return
     */
    @PostMapping
    public ResultJson OssfileUpload(MultipartFile file) {
        // 上传照片并返回  在oss的路径
        String ossUrl = iOssService.uploadFileAvatar(file);
//        System.out.println(ossUrl);
        if(ObjectUtils.isEmpty(ossUrl)){
            return ResultJson.error().data("message","头像上传失败！");
        }
        return ResultJson.success().data("varatarUrl",ossUrl);
    }

}
